/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.actions;

import com.myapp.bd.QueryBD;
import com.myapp.forms.AjoutStageForm;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author Fabien
 */
public class CreerStageAction extends Action {

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws SQLException {
        //il s'agit du cas ou la personne clique sur creer stage dans le menu(pas de form associé)
        
        AjoutStageForm cf = (AjoutStageForm) form;
        if(cf.getChoix()==null) {
        QueryBD queryBD = new QueryBD();
        ArrayList listEtudiants = (ArrayList) queryBD.recupListeEtudiantParPromo(cf.getPromotion());
        request.setAttribute("listEtudiants", listEtudiants);
        return mapping.findForward("rechercheListPromo");
        }
        //sinon le cas ou il clique sur creer stage a coté du nom de l'etudiant
        else {   
         // instanciation d'un stage pour l'etudiant
         QueryBD queryBD = new QueryBD();
         queryBD.creerStage(cf.getnCandidat());
         return mapping.findForward("stageCree");
         }
    }
}
